﻿using ControlzEx.Theming;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using Microsoft.VisualBasic;
using Prism.Regions;
using System.Windows;
using System.Windows.Controls;

namespace MetroApp.Web.Views
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : MetroWindow
    {
        private readonly IRegionManager _regionManager;

        public MainWindow(IRegionManager regionManager)
        {
            InitializeComponent();

            //ThemeManager.Current.ChangeTheme(this, "Light.Blue");//"Dark.Red"

            //切换主题ThemeManager.Current.ChangeTheme(this, "Light.Blue");//"Dark.Red"

            ThemeManager.Current.ChangeTheme(Application.Current, "Light.Blue");
            _regionManager = regionManager;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnButton_ChangeTheme(object sender, RoutedEventArgs e)
        {
            //切换系统主题,通过按钮Tag 传入属性值
            var senderButton = sender as Button;
            if (senderButton != null)
            {
                ThemeManager.Current.ChangeTheme(Application.Current, senderButton.Tag.ToString());              
            }
            //ThemeManager.Current.ChangeTheme(this, "Light.Blue");//"Dark.Red"
        }

        private async void OnButtonClick(object sender, RoutedEventArgs e)
        {
            await this.ShowMessageAsync("This is the title", "Some message");
        }

        private void FlipView_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            var flipview = ((FlipView)sender);
            switch (flipview.SelectedIndex)
            {
                case 0:
                    flipview.BannerText = "Cupcakes!";
                    break;
                case 1:
                    flipview.BannerText = "Xbox!";
                    break;
                case 2:
                    flipview.BannerText = "Chess!";
                    break;
            }
        }

        private void LaunchGitHubSite(object sender, RoutedEventArgs e)
        {

        }

        private void DeployCupCakes(object sender, RoutedEventArgs e)
        {

        }

        private void BtnShow_MorePage(object sender, RoutedEventArgs e)
        {
            //无法跳转到页面Hamburger，因为Hamburger不是UserControl，也不是Page
            //_regionManager.RequestNavigate("ContentRegion", "Hamburger");

            var hamburgerWindow = new MetroApp.Web.Views.Hamburger();
            hamburgerWindow.Show();

        }

        private void ThemeSelector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ThemeSelector.SelectedItem is ComboBoxItem item && item.Tag is string theme)
            {
                // theme 格式 "Base.Color"
                var split = theme.Split('.');
                if (split.Length == 2)
                {
                    var cur = Application.Current;
                    ThemeManager.Current.ChangeTheme(Application.Current, $"{split[0]}.{split[1]}");
                    //ThemeManager.Current.ChangeTheme(this, $"{split[0]}.{split[1]}");
                }
            }
        }
    }
}
